package cn.glow.readingcloud.book.service.impl;
import  cn.glow.readingcloud.common.pojo.Book;

import cn.glow.readingcloud.book.dao.CategoryMapper;
import cn.glow.readingcloud.book.service.CategoryService;
import cn.glow.readingcloud.common.result.Result;
import cn.glow.readingcloud.common.result.ResultUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pojo.Category;
import pojo.CategoryView;

/**
 * @Author Glow
 * @Date 2023-04-15 23:17:42
 * @Description
 * @Version 1.0
 */
@Service
public class CategoryServiceImpl  extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;


    @Override
    public Result<CategoryView> getDicTypeNameAndCodeName(String dicType, Integer code) {
        LambdaQueryWrapper<Category> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Category::getDicType,dicType);
        queryWrapper.eq(Category::getCode,code);
        Category category = categoryMapper.selectOne(queryWrapper);
        CategoryView categoryView = new CategoryView();
        BeanUtils.copyProperties(category,categoryView);
        return ResultUtil.success(categoryView);
    }
}
